home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM 1
/
LIGHT-ROM 1 (Amiga Library Services)(1994).iso
/
ffdisks
/
d978.lha
/
NewEdit
/
Source
/
Hook.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-03
|
11KB
|
287 lines
/*----------------------------------------------------------------------------
File : Hook.c
Projekt: NewEdit
Inhalt : next_word()
prev_word()
string_hook()
Version: 1.5
Datum : 18. August 1992
Autor : Uwe Röhm
Adresse: Auber Str. 25, W-6209 Hohenstein 4
(Semester) Wörthstr. 18 W-8390 Passau
Bemerkung:
Neue globale String-Hook, die verschiedene Cursorfunktionen, Abbruch per
ESC-Taste und vorallem Copy und Paste per Clipboard unterstuetzt!
Benoetigt Funktionen aus ClipBoard.c!!!!
----------------------------------------------------------------------------*/
#include <intuition/sghooks.h>
#include <intuition/intuition.h>
#include <devices/inputevent.h>
#include <exec/semaphores.h>
/* ------------------------ Prototypes & Pragmas ------------------------ */
#include <clib/exec_protos.h>
#include <clib/utility_protos.h>
#include <string.h>
#include <ctype.h>
#ifdef LATTICE
#include <pragmas/exec_pragmas.h>
#include <pragmas/utility_pragmas.h>
#endif
/* ------------------------- externe Funktionen ------------------------- */
extern ULONG read_clip ( UBYTE *, ULONG );
extern void write_clip( UBYTE *, ULONG );
/* --------------------------- eigene Defines --------------------------- */
#define IECODE_UNUSED 0
#define IECODE_C 51
#define IECODE_V 52
#define IECODE_RETURN 68
#define IECODE_ESC 69
#define IECODE_BACKSP 65
#define IECODE_DEL 70
#define IECODE_CRSRUP 76
#define IECODE_CRSRDWN 77
#define IECODE_CRSRRIGHT 78
#define IECODE_CRSRLEFT 79
#define IECODE_HELP 95
#ifndef SGA_NEXTACTIVE
#define SGA_NEXTACTIVE (0x20L) /* Make next possible gadget active. */
#define SGA_PREVACTIVE (0x40L) /* Make previous possible gadget active.*/
#endif
/* ---------------------------- globale Vars ---------------------------- */
extern struct Library *SysBase;
extern struct Library *DOSBase;
extern struct Library *UtilityBase;
extern struct Hook *OldHook;
extern char *SemaphoreName;
extern struct SignalSemaphore *Sem;
extern BOOL Disabled;
/*
* Zwei kleine Hilfsfunktionen für die Stringhook unten
* zum Bewegen/Loeschen im Stinggadget
*/
LONG next_word ( UBYTE *buffer, LONG pos, LONG max )
{
while ( pos < max && !isspace(buffer[ pos ]))
pos++;
while ( pos < max && isspace(buffer[ pos ]))
pos++;
return pos;
}
LONG prev_word ( UBYTE *buffer, LONG pos )
{
while ( pos > 0 && isspace(buffer[ pos - 1 ]))
pos--;
while ( pos > 0 && !isspace(buffer[ pos - 1 ]))
pos--;
return pos;
}
/****** string_hook() *******************************************************
*
* NAME
* string_hook -- general EditHook for Gadtools Stringgadgets
* SYNOPSIS
* Known = string_hook ( Hook, Object, Message )
* D0 A0 A2 A1
* ULONG string_hook ( struct Hook *, struct SGWork *, APTR * );
* FUNCTION
* Normally set as new global Hook with SetEditHook().
* The following functions will be supported:
* SHIFT CURSOR RIGHT next word
* SHIFT CURSOR LEFT previous word
* ALT BACKSPACE delete previous word
* ALT DEL delete next word
* RALT CURSOR UP go to prev gadget (with GADGETUP)
* RALT CURSOR DOWN go to next gadget (with GADGETUP)
* ESC leave gadget (with GADGETUP)
* RCommand C copy gadget contents to clipboard 0
* RCommand V paste contents of clip 0 to gadget
* sgw->EditOp will be set to EO_BIGCHANGE, if some text has been
* deleted or inserted from the clipboard.
* sgw->IEvent->ie_Code will be motified to 0x00 if we moved to the
* next/previous word/gadget or if AMIGA-C or AMIGA-V was pressed. The
* keycode 0 is unused by the system and therefor will be ignored by
* further stringhooks.
* INPUTS
* Hook - pointer to own hook-structure
* Object - struct SGWork for Stringgadgets
* Message- ???
* RESULT
* ~0 - command supported, else 0
* sgw->EditOp and sgw->IEvent->ie_Code may be motified (see above)
* DATE
* 18. April 1992
*****************************************************************************
*/
ULONG __saveds __asm string_hook( register __a0 struct Hook *hook,
register __a2 struct SGWork *sgw,
register __a1 unsigned long *msg )
{
struct InputEvent *ie;
ULONG length;
ULONG return_code = ~0;
/*
* Einen shared Lock auf die Semaphore.
* Damit können theoretisch mehrere Stringhooks gleichzeitig
* aktiviert sein. Das Hauptprogramm kann aber keinen exklusiven
* Lock bekommen, solange auch nur ein shared Lock noch aktiv ist.
*/
ObtainSemaphoreShared( Sem );
if ( *msg == SGH_KEY )
{
/*
* Zuerst abfragen, ob NewEdit momentan disabled ist
*/
if ( !Disabled )
{
ie = sgw->IEvent;
if ( ie->ie_Class == IECLASS_RAWKEY )
{
switch (ie->ie_Code)
{
case IECODE_ESC:
sgw->Actions |= SGA_END;
break;
case IECODE_CRSRUP:
if ( ie->ie_Qualifier & IEQUALIFIER_RALT )
{
sgw->Actions |= SGA_PREVACTIVE | SGA_END;
ie->ie_Code = IECODE_UNUSED;
} /* if IEQUALIFIER_RSHIFT */
break;
case IECODE_CRSRDWN:
if ( ie->ie_Qualifier & IEQUALIFIER_RALT )
{
sgw->Actions |= SGA_NEXTACTIVE | SGA_END;
ie->ie_Code = IECODE_UNUSED;
} /* if IEQUALIFIER_RSHIFT */
break;
case IECODE_CRSRRIGHT:
if ( ie->ie_Qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT) )
{
sgw->BufferPos= next_word( sgw->WorkBuffer, sgw->BufferPos, sgw->StringInfo->NumChars );
ie->ie_Code = IECODE_UNUSED;
sgw->Actions |= SGA_REDISPLAY;
} /* if IEQUALIFIER_LALT */
break;
case IECODE_CRSRLEFT:
if ( ie->ie_Qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT) )
{
sgw->BufferPos= prev_word ( sgw->WorkBuffer, sgw->BufferPos );
ie->ie_Code = IECODE_UNUSED;
sgw->Actions |= SGA_REDISPLAY;
} /* if IEQUALIFIER_LALT */
break;
case IECODE_BACKSP:
if ( ie->ie_Qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT) )
{
sgw->BufferPos = prev_word ( sgw->WorkBuffer, sgw->BufferPos ) + 1;
if ( sgw->BufferPos < sgw->StringInfo->BufferPos )
strcpy ( &sgw->WorkBuffer[ sgw->BufferPos ], &sgw->WorkBuffer[ sgw->StringInfo->BufferPos ] );
sgw->Actions |= SGA_REDISPLAY;
sgw->EditOp = EO_BIGCHANGE;
} /* if IEQUALIFIER_LALT */
break;
case IECODE_DEL:
if ( ie->ie_Qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT) )
{
length = next_word( sgw->WorkBuffer, sgw->BufferPos, sgw->StringInfo->NumChars );
strcpy ( &sgw->WorkBuffer[ sgw->BufferPos + 1 ], &sgw->WorkBuffer[ length ] );
sgw->Actions |= SGA_REDISPLAY;
sgw->EditOp = EO_BIGCHANGE;
} /* if IEQUALIFIER_LALT */
break;
default:
/* Test, ob rechte Amiga-Taste gedrueckt wurde */
if (ie->ie_Qualifier & IEQUALIFIER_RCOMMAND)
{
/* RCommand zusammen mit V: Paste from Clipboard */
if ( ie->ie_Code == IECODE_V )
{
/*
* Inhalt des Clipboards an die aktuelle Cursorposition
* einlesen. Dazu wird zuerst alles hinter dem Cursor an
* das Bufferende kopiert und nach dem Einfügen zurueck-
* geschoben.
*/
WORD maxchars;
WORD pos;
maxchars = sgw->StringInfo->MaxChars - 1;
pos = sgw->NumChars;
while ( --pos >= sgw->BufferPos )
sgw->WorkBuffer[ maxchars - sgw->NumChars + pos ] = sgw->WorkBuffer[ pos ];
length = read_clip ( &sgw->WorkBuffer[sgw->BufferPos], maxchars - sgw->NumChars );
if ( length > 0 )
{
strcpy ( &sgw->WorkBuffer[ sgw->BufferPos + length ],
&sgw->WorkBuffer[ maxchars - sgw->NumChars + sgw->BufferPos ] );
sgw->BufferPos += length;
sgw->NumChars += length;
} /* if length > 0 */
else
sgw->Actions |= SGA_BEEP;
sgw->EditOp = EO_BIGCHANGE;
sgw->Code = IECODE_UNUSED; /* aktuelle Taste auf No-Op umbiegen!! */
} /* if IECODE_V */
/* RCommand zusammen mit C: Copy into Clipboard */
else if ( ie->ie_Code == IECODE_C )
{
write_clip ( sgw->StringInfo->Buffer, sgw->NumChars );
sgw->Code = IECODE_UNUSED; /* aktuelle Taste auf No-Op umbiegen!! */
} /* if IECODE_C */
} /* if IEQUALIFIER_RCOMMAND */
break;
} /* switch */
} /* else EditOp */
} /* if !Disabled */
/*
* Die originale Edithook von Intuition aufrufen, damit
* das Stringgadget auch korrekt refreshed wird.
*/
CallHookPkt( OldHook, (APTR) sgw, msg);
} /* if SGH_KEY */
else
return_code = 0;
ReleaseSemaphore( Sem );
return return_code;
}